<?php
namespace App\Http\Controllers\v1;

use Illuminate\Http\Request;
use Mockery\Exception;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Http\Controllers\RequestBackController;
use App\Http\Controllers\Controller;
use App\Http\Controllers\CheckController;
use App\Http\Controllers\v1\PurviewController;


class GroupController extends Controller
{
    public function GroupInfo($request)
    {
        if(!CheckController::CheckUser($request))
        {
            return RequestBackController::Structure(205);
        }
        $pos=$request->all();
        if(!CheckController::CheckParameter($pos,['UserId']))
        {
            return RequestBackController::Structure(502);
        }
        $res=DB::table('yl_user as u')->join('yl_group as g','g.group_id','=','u.group_id')
            ->select('g.group_id as GroupId','g.group_name as GroupName','g.group_short_name as GroupShortName','g.group_contact as GroupContact','group_address as GroupAddress')
            ->where('u.user_id',$pos['UserId'])
            ->first();
        return RequestBackController::Structure(101,$res);
    }
    public function GroupUpdate($request)
    {
        if(!CheckController::CheckUser($request))
        {
            return RequestBackController::Structure(205);
        }
        $pos=$request->all();
        if(!CheckController::CheckParameter($pos,['GroupId','GroupName','GroupShortName','GroupContact','GroupAddress']))
        {
            return RequestBackController::Structure(502);
        }
        $arr=[
            'group_name'=>$pos['GroupName'],
            'group_short_name'=>$pos['GroupShortName'],
            'group_contact'=>$pos['GroupContact'],
            'group_address'=>$pos['GroupAddress']
        ];
        DB::table('yl_group')->where('group_id',$pos['GroupId'])->update($arr);
        return RequestBackController::Structure(101);
    }
    public function GroupList($request)
    {
        if(!CheckController::CheckUser($request))
        {
            return RequestBackController::Structure(205);
        }
        $res=DB::table('yl_group')->select('group_id as GroupId','group_name as GroupName')->get();
        return RequestBackController::Structure(101,$res);
    }
}